﻿@using Microsoft.AspNetCore.Mvc.Controllers
@using Grand.Core
@using Grand.Core.Plugins
@using Grand.Services.Authentication.External
@using Grand.Services.Cms
@using Grand.Services.Common
@using Grand.Services.Payments
@using Grand.Services.Shipping
@using Grand.Services.Tax
@inject IPluginFinder pluginFinder
@inject IWebHelper webHelper
@inject IServiceProvider serviceProvider    
@{
    var plugin = PluginManager.FindPlugin((this.ViewContext.ActionDescriptor as ControllerActionDescriptor).ControllerTypeInfo.AsType()).Instance(serviceProvider);
    var menuitem = "";

    //friendly name
    var friendlyName = plugin?.PluginDescriptor.FriendlyName;

    var activeMenuSystemName = string.Empty;
    var configureLocale = string.Empty;
    var backToLocale = string.Empty;
    var listActionMethodName = string.Empty;
    var listControllerName = string.Empty;

    if (plugin is IPaymentMethod)
    {
        //payment plugin
        activeMenuSystemName = "Payment methods";
        configureLocale = "Admin.Configuration.Payment.Methods.Configure";
        backToLocale = "Admin.Configuration.Payment.Methods.BackToList";
        listActionMethodName = "Methods";
        listControllerName = "Payment";
        menuitem = "/Admin/Payment/Methods";
    }
    else if (plugin is IShippingRateComputationMethod)
    {
        //shipping rate computation method
        activeMenuSystemName = "Shipping providers";
        configureLocale = "Admin.Configuration.Shipping.Providers.Configure";
        backToLocale = "Admin.Configuration.Shipping.Providers.BackToList";
        listActionMethodName = "Providers";
        listControllerName = "Shipping";
        menuitem = "/Admin/Shipping/Providers";
    }
    else if (plugin is ITaxProvider)
    {
        //tax provider
        activeMenuSystemName = "Tax providers";
        configureLocale = "Admin.Configuration.Tax.Providers.Configure";
        backToLocale = "Admin.Configuration.Tax.Providers.BackToList";
        listActionMethodName = "Providers";
        listControllerName = "Tax";
        menuitem = "/Admin/Tax/Providers";
    }
    else if (plugin is IExternalAuthenticationMethod)
    {
        //external auth method
        activeMenuSystemName = "External authentication methods";
        configureLocale = "Admin.Configuration.ExternalAuthenticationMethods.Configure";
        backToLocale = "Admin.Configuration.ExternalAuthenticationMethods.BackToList";
        listActionMethodName = "Methods";
        listControllerName = "ExternalAuthentication";
        menuitem = "/Admin/ExternalAuthentication/Methods";
    }
    else if (plugin is IWidgetPlugin)
    {
        //widgets
        activeMenuSystemName = "Widgets";
        configureLocale = "Admin.ContentManagement.Widgets.Configure";
        backToLocale = "Admin.ContentManagement.Widgets.BackToList";
        listActionMethodName = "List";
        listControllerName = "Widget";
        menuitem = "/Admin/Widget/List";
    }
    else if (plugin is IMiscPlugin)
    {
        //Misc plugins
        activeMenuSystemName = "Local plugins";
        configureLocale = "Admin.Configuration.Plugins.Misc.Configure";
        backToLocale = "Admin.Configuration.Plugins.Misc.BackToList";
        listActionMethodName = "List";
        listControllerName = "Plugin";
        menuitem = "/Admin/Plugin/List";
    }

    Layout = "_AdminLayout";
    //page title
    ViewBag.Title = T(configureLocale).Text + " - " + friendlyName;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName(activeMenuSystemName);

}
<input id="active-menu-item" type="hidden" value="@menuitem" />
<div class="row">
    <div class="col-md-12">
        <div class="x_panel light form-fit">
            <div class="x_title">
                <div class="caption caption-flex">
                    <i class="fa fa-tasks"></i>
                    <div class="captionText">@T(configureLocale) - @friendlyName</div>
                    <small><i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(T(backToLocale).Text, listActionMethodName, listControllerName)</small>
                </div>
            </div>
            <div class="x_content form">
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="x_content">
                            @RenderBody()
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>